﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AvoidForgetting.Entities.Dtos;
using AvoidForgetting.Entities.Models.Org;
using AvoidForgetting.JWT;
using FreeSql;
using JWTToken.Filter;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace AvoidForgetting.Controllers
{
    /// <summary>
    /// Organization
    /// </summary>
    [ServiceFilter(typeof(TokenFilter))]
    public class OrgController : CommonBaseController
    {
        BaseRepository<OrgDto> resOrg;
        private readonly ITokenHelper tokenHelper = null;

        /// <summary>
        /// ctos
        /// </summary>
        /// <param name="_tokenHelper"></param>
        /// <param name="_resOrg"></param>
        public OrgController(ITokenHelper _tokenHelper, BaseRepository<OrgDto> _resOrg)
        {
            tokenHelper = _tokenHelper;
            resOrg = _resOrg;
        }


        /// <summary>
        /// 获取数据库信息
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetOrgs(string name)
        {
            var orgList = string.IsNullOrEmpty(name)? resOrg.Select.Where(o=>o.IsDeleted == 0).ToListAsync(): resOrg.Select.Where(o => o.IsDeleted == 0&&o.Name.Contains(name)).ToListAsync();
            return Ok(await orgList);
        }


        /// <summary>
        /// 更改
        /// </summary>
        /// <param name="changeOrgStart"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> EnableOrg([FromBody] ChangeOrgStart changeOrgStart)
        {
            resOrg.Update(
            return Ok("");
        }
    }
}
